//
//  CJCommentCollectionViewCell.m
//  CoJellyCartoon
//
//  Created by dllo on 16/4/7.
//  Copyright © 2016年 CJG. All rights reserved.
//

#import "CJCommentCollectionViewCell.h"
#import "CJCommentTableViewCell.h"
#import "CJCommentReplies.h"
@interface CJCommentCollectionViewCell ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, strong) UITableView *commentTableView;
@property (nonatomic, strong) CJCommentTableViewCell *commentcell;
@property (nonatomic, assign) BOOL isScrolled;
@end
@implementation CJCommentCollectionViewCell


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
    if (self) {
        [self creatTableView];
        
    }
    
    return self;
}

-(void)creatTableView{
    
    
    self.commentTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    self.commentTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.commentTableView.dataSource = self;
    
    self.commentTableView.delegate = self;
    
    self.commentTableView.scrollEnabled = YES;
    [self.commentTableView registerClass:[CJCommentTableViewCell class] forCellReuseIdentifier:@"CJCommentTableViewCell"];
    
    [self addSubview:self.commentTableView];
    
    
}

-(void)layoutSubviews{
    
    self.commentTableView.frame = CGRectMake(0, -40, self.bounds.size.width, self.bounds.size.height);
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.commentModel.replies.count;
    
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    CJCommentReplies *replayModel = self.commentModel.replies[indexPath.row];
    
    self.commentcell = [tableView dequeueReusableCellWithIdentifier:@"CJCommentTableViewCell"];
    self.commentcell.commentReplyModel = replayModel;
    return self.commentcell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return self.bounds.size.height / 6;
}

-(void)setCommentModel:(CJCommentModel *)commentModel{
    
    _commentModel = commentModel;
    
    [self.commentTableView reloadData];
    
}

@end
